package com.csu.server.module.msgProcess;

import java.util.ArrayList;
import java.util.List;

import com.csu.message.BaseMessage;
import com.csu.message.TalkMessage;
import com.csu.server.module.ServerCache;
import com.csu.server.module.UserConnect;

public class TalkMessageProcess implements IMessageProcess {

	public void processMessage(BaseMessage message) {
		TalkMessage talkMessage=(TalkMessage)message;
		String destQQ=talkMessage.getDestQQ();
		ServerCache cache=ServerCache.getInstance();
		UserConnect userConnect=cache.getUserConnectMap().get(destQQ);
		if(userConnect!=null){
			userConnect.sendTextMessage(talkMessage);
		}else{
			List<BaseMessage> leaveMsgList=cache.getAllLeaveMessageMap().get(destQQ);
			if(leaveMsgList==null){
				leaveMsgList=new ArrayList<BaseMessage>();
			}
				leaveMsgList.add(talkMessage);
				cache.getAllLeaveMessageMap().put(destQQ, leaveMsgList);
		}
	}

}
